home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr40 / x1j4_src.zip / IP.H < prev    next >
Text File  |  1995-01-20  |  10KB  |  324 lines

  1. /*****************************************************************************/
  2. /*                                              */
  3. /*                                         */
  4. /*    *****              *****                      */
  5. /*     *****            *****                         */
  6. /*       *****          *****                         */
  7. /*         *****        *****                         */
  8. /*  ***************      ***************                     */
  9. /*  *****************    *****************                     */
  10. /*  ***************      ***************                     */
  11. /*         *****        *****       TheNet                    */
  12. /*       *****          *****       Portable. Compatible.         */
  13. /*     *****            *****       Public Domain             */
  14. /*    *****              *****    G8KBB                  */
  15. /*                                         */
  16. /* This software is public domain ONLY for non commercial use                */
  17. /*                                                                           */
  18. /*                                         */
  19. /*****************************************************************************/
  20.  
  21. /* Level 3, Internet Gateway Header file                     */
  22. /* Version 1.00                                                              */
  23. /* Dave Roberts G8KBB, 7, Rowanhayes Close, Ipswich, England             */
  24. /* 10-April-91                                     */
  25. /* This software is released into the public domain on the understanding
  26.  * that it is to be used only for non life threatening, amateur, non 
  27.  * commercial purposes only. 
  28.  * It has been written expressly for use in self tuition of
  29.  * people in amateur radio communications only. It is NOT claimed that this
  30.  * software works correctly. 
  31.  *
  32.  * USELONG, if defined, causes long integers to be used where appropriate
  33.  * so failing to define it will avoid longs completely !
  34.  *
  35.  * BYTE and WORD ordering are fixed, and need generalisation !
  36.  *
  37.  *
  38.  * Released as TheNet X-1J, September 1993
  39.  *
  40.  * Released as TheNet X-1J release 4, January 1995
  41.  */
  42.  
  43. /* IP protocol field values */
  44. #define    ICMP_PTCL    1    /* Internet Control Message Protocol */
  45. #define    TCP_PTCL    6    /* Transmission Control Protocol */
  46. #define    UDP_PTCL    17    /* User Datagram Protocol */
  47. #define    RSPF_PTCL    73    /* Radio Shortest Path First Protocol */
  48.  
  49. #define    MAXTTL        255    /* Maximum possible IP time-to-live value */
  50.  
  51. /* DoD-style precedences */
  52. #define    ROUTINE        0x00
  53. #define    PRIORITY    0x20
  54. #define    IMMEDIATE    0x40
  55. #define    FLASH        0x60
  56. #define    FLASH_OVER    0x80
  57. #define    CRITIC        0xa0
  58. #define    INET_CTL    0xc0
  59. #define    NET_CTL        0xe0
  60.  
  61. /* Amateur-style precedences */
  62. #define    AM_ROUTINE    0x00
  63. #define    AM_WELFARE    0x20
  64. #define    AM_PRIORITY    0x40
  65. #define    AM_EMERGENCY    0x60
  66.  
  67. /* Class-of-service bits */
  68. #define    LOW_DELAY    0x10
  69. #define    THROUGHPUT    0x08
  70. #define    RELIABILITY    0x04
  71.  
  72. /* IP TOS fields */
  73. #define    PREC(x)        ((x)>>5 & 7)
  74. #define    DELAY        0x10
  75. #define    THRUPUT        0x8
  76. #define    RELIABLITY    0x4
  77.  
  78. /* structure for an ip address ( avoid longs !!!! ) */
  79.  
  80. typedef union ip_addr_
  81. {
  82.     unsigned long Long;
  83.     unsigned int  Short[2];
  84.     unsigned char Bytes[4];
  85. } ipaddr;
  86.  
  87. /* Format of a MIB entry for statistics gathering */
  88. struct mib_entry {
  89. /*    char *name;
  90. */    struct {
  91.         unsigned integer;
  92.     } value;
  93. };
  94.  
  95. #define    TLB    30    /* Default reassembly timeout, sec */
  96. #define    IPVERSION    4
  97. #define    IP_MAXOPT    40    /* Largest option field, bytes */
  98.  
  99. #define    ipL2Modes        Ip_mib[0].value.integer
  100. /* SNMP MIB variables, used for statistics and control. See RFC 1066 */
  101. #define    ipForwarding        Ip_mib[1].value.integer
  102. #define    ipDefaultTTL        Ip_mib[2].value.integer
  103. #define    ipInReceives        Ip_mib[3].value.integer
  104. #define    ipInHdrErrors        Ip_mib[4].value.integer
  105. #define    ipInAddrErrors        Ip_mib[5].value.integer
  106. #define    ipForwDatagrams        Ip_mib[6].value.integer
  107. #define    ipInUnknownProtos    Ip_mib[7].value.integer
  108. #define    ipInDiscards        Ip_mib[8].value.integer
  109. #define    ipInDelivers        Ip_mib[9].value.integer
  110. #define    ipOutRequests        Ip_mib[10].value.integer
  111. #define    ipOutDiscards        Ip_mib[11].value.integer
  112. #define    ipOutNoRoutes        Ip_mib[12].value.integer
  113. #define    ipReasmTimeout        Ip_mib[13].value.integer
  114. #define    ipReasmReqds        Ip_mib[14].value.integer
  115. #define    ipReasmOKs        Ip_mib[15].value.integer
  116. #define    ipReasmFails        Ip_mib[16].value.integer
  117. #define    ipFragOKs        Ip_mib[17].value.integer
  118. #define    ipFragFails        Ip_mib[18].value.integer
  119. #define    ipFragCreates        Ip_mib[19].value.integer
  120.  
  121. #define    NUMIPMIB    19
  122.  
  123. /* IP header, INTERNAL representation */
  124. typedef struct ip_ {
  125.     unsigned char version;        /* IP version number */
  126.     unsigned char tos;        /* Type of service */
  127.     unsigned length;        /* Total length */
  128.     unsigned id;            /* Identification */
  129.     unsigned offset;        /* Fragment offset in bytes */
  130.     struct {
  131.         unsigned char df;    /* Don't fragment flag */
  132.         unsigned char mf;    /* More Fragments flag */
  133.     } flags;
  134.  
  135.     unsigned char ttl;        /* Time to live */
  136.     unsigned char protocol;        /* Protocol */
  137.     unsigned checksum;        /* Header checksum */
  138.     ipaddr source;            /* Source address */
  139.     ipaddr dest;            /* Destination address */
  140.     unsigned char options[IP_MAXOPT];/* Options field */
  141.     unsigned optlen;        /* Length of options field, bytes */
  142. } IP;
  143.  
  144. #define    NULLIP    (IP *)0
  145. #define    IPLEN    20    /* Length of standard IP header */
  146.  
  147. /* Fields in option type byte */
  148. #define    OPT_COPIED    0x80    /* Copied-on-fragmentation flag */
  149. #define    OPT_CLASS    0x60    /* Option class */
  150. #define    OPT_NUMBER    0x1f    /* Option number */
  151.  
  152. /* IP option numbers */
  153. #define    IP_EOL        0    /* End of options list */
  154. #define    IP_NOOP        1    /* No Operation */
  155. #define    IP_SECURITY    2    /* Security parameters */
  156. #define    IP_LSROUTE    3    /* Loose Source Routing */
  157. #define    IP_TIMESTAMP    4    /* Internet Timestamp */
  158. #define    IP_RROUTE    7    /* Record Route */
  159. #define    IP_STREAMID    8    /* Stream ID */
  160. #define    IP_SSROUTE    9    /* Strict Source Routing */
  161.  
  162. /* Timestamp option flags */
  163. #define    TS_ONLY        0    /* Time stamps only */
  164. #define    TS_ADDRESS    1    /* Addresses + Time stamps */
  165. #define    TS_PRESPEC    3    /* Prespecified addresses only */
  166.  
  167. /* structure for routing tables */
  168.  
  169. typedef struct iproute_
  170. {
  171.     ipaddr dest;
  172.     ipaddr gateway;
  173.     unsigned metric;
  174.     unsigned timer;
  175.     unsigned char bits;
  176.     unsigned char interface;
  177.     unsigned char flags;
  178. #define    RTPRIVATE    0x1    /* Should the world be told of this route ? */
  179. #define    RTTRIG    0x2        /* Trigger is pending for this route */
  180.     unsigned char spare_byte;
  181. } IP_ROUTE;
  182.  
  183. typedef struct iproutemb
  184. {
  185.     lhtyp link;
  186.     IP_ROUTE route;
  187. } IP_ROUTE_MB;
  188.  
  189. #define    NULLROUTE    (IP_ROUTE *)0
  190.  
  191.  
  192. /* Cache for the last-used routing entry, speeds up the common case where
  193.  * we handle a burst of packets to the same destination
  194.  */
  195. struct rt_cache {
  196.     ipaddr target;
  197.     IP_ROUTE *route;
  198. };
  199.  
  200. typedef struct i_face_
  201. {
  202.     unsigned (*func)();    /* output handler for sending */
  203. #ifdef MOD_MTU
  204.     unsigned *mtu;        /* pointer to max MTU before fragmentation */
  205. #else
  206.     unsigned mtu;        /* max MTU before fragmentation */
  207. #endif
  208. /*    ipaddr *bcast;           broadcast address for this interface */
  209.     unsigned hwtype;
  210.     unsigned port;        /* hardware port number */
  211. } I_FACE;
  212.  
  213. #define MAXINTERFACES 3
  214.  
  215. typedef struct arp_tab_
  216. {
  217.     ipaddr dest;
  218.     char callsign[7];
  219.     unsigned timer;
  220.     char dgmode;
  221.     char hwtype;
  222.     char publish_flag;
  223.     char state;
  224. } ARP_TAB;
  225.  
  226. typedef struct arp_tab_mb
  227. {
  228.     lhtyp link;
  229.     ARP_TAB arp;
  230. } ARP_TAB_MB;
  231.  
  232. #define NULLARP (ARP_TAB *)0
  233.  
  234. #define ARP_NETROM 0
  235. #define ARP_AX25 3
  236.  
  237. #define MAXHWALEN 10
  238. #define IPTYPE 42
  239.  
  240. #define ARP_REQUEST    1
  241. #define ARP_REPLY      2
  242. #define REVARP_REQUEST 3
  243. #define REVARP_REPLY   4
  244.  
  245. #define ARP struct arp_
  246. ARP
  247. {
  248.     unsigned hardware;
  249.     unsigned protocol;
  250.     unsigned char hwalen;
  251.     unsigned char pralen;
  252.     unsigned opcode;
  253.     unsigned char shwaddr[MAXHWALEN];
  254.     ipaddr sprotaddr;
  255.     unsigned char thwaddr[MAXHWALEN];
  256.     ipaddr tprotaddr;
  257. };
  258.  
  259. #define NULLBUF ( void * )0
  260.  
  261. /* Pseudo-header for TCP and UDP checksumming */
  262. struct pseudo_header {
  263.     ipaddr source;        /* IP source */
  264.     ipaddr dest;        /* IP destination */
  265.     unsigned char protocol;        /* Protocol */
  266.     unsigned length;        /* Data field length */
  267. };
  268. #define    NULLHEADER    (struct pseudo_header *)0
  269.  
  270. #ifndef USELONG
  271. typedef union cksum_
  272. {
  273.     unsigned long Long;
  274.     unsigned int  Short[2];
  275. } CK_SUM;
  276. #endif
  277.  
  278. /* From tnl7ip.c
  279.  */
  280. int ccpipr(void);
  281. int showroute(struct iproute_ *,struct mhead *);
  282. int show_ip_addr(union ip_addr_ *,struct mhead *);
  283. int get_ip_addr(union ip_addr_ *,int *,char * *);
  284. int ccparp(void);
  285. int showarp(struct arp_tab_ *,struct mhead *);
  286. int ccpipa(void);
  287. int ccpipb(void);
  288. int ccpips(void);
  289. int rt_add(union ip_addr_ *,unsigned int ,union ip_addr_ *,int ,unsigned int ,unsigned int ,unsigned int );
  290. int route_find(struct iproutemb * *,union ip_addr_ *,union ip_addr_ *,unsigned int );
  291. int rt_drop(union ip_addr_ *,unsigned int );
  292. int arp_add(union ip_addr_ *,unsigned int ,char *,unsigned int ,unsigned int ,unsigned int );
  293. int find_arp(struct arp_tab_mb * *,union ip_addr_ *, unsigned int );
  294. int arp_drop(union ip_addr_ *, unsigned int);
  295.  
  296. /* From iproute.c
  297.  */
  298. int ipinit(void );
  299. int ipserv(void );
  300. int ip_route( struct mhead * );
  301. int is_my_ip_addr(union ip_addr_ *);
  302. int is_broadcast_address(union ip_addr_ *);
  303. struct iproute_ *rt_find(union ip_addr_ *);
  304. unsigned nr_iface(struct mhead *,unsigned int ,union ip_addr_ *,unsigned int );
  305. unsigned l2_iface(struct mhead *,unsigned int ,union ip_addr_ *,unsigned int );
  306. struct arp_tab_ *res_arp(union ip_addr_ *,unsigned int );
  307. unsigned int get16(struct mhead *);
  308. int put16(unsigned int ,struct mhead *);
  309. struct mhead *htonip(struct ip_ *,struct mhead *, BOOLEAN );
  310. int ip_send(union ip_addr_ *,union ip_addr_ *,unsigned ,unsigned ,unsigned ,struct mhead *,unsigned short ,unsigned short ,unsigned );
  311. #ifdef USELONG
  312. unsigned short eac(long );
  313. #else
  314. unsigned short eac(void );
  315. #endif
  316. unsigned short cksum(struct pseudo_header *,struct mhead *,unsigned short );
  317.  
  318. #ifdef MSDOS
  319. #define addsum( x ) ( ip_cksum.Long += (x) )
  320. #endif
  321.  
  322. void *allocb();
  323. mhtyp *gennhd();
  324.